# 页面的操作 比如查找元素 输入元素 获取元素属性 等等
import logging

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait


class BasePage:
    def __init__(self,driver):
        self.__driver=driver

    #查找页面元素
    def find_page_element(self,loc:tuple) -> WebElement:
        #给定位添加显示等待  ------>返回的是查找的元素
        try:

            el=WebDriverWait(self.__driver,10).until(lambda x:x.find_element(*loc))
            logging.info(f"excute find_el {loc} success!")
        except Exception as e:
            logging.info(f"excute find_el {loc} failed!")
            el=None

        return  el



    #输入页面元素
    # loc：定位方式,页面中元素的值
    # value:我们往输入框输入的值
    def input_page_element(self,loc:tuple,value):
        ele= self.find_page_element(loc)
        try:
           ele.send_keys(value)
           logging.info(f"excute input {ele}'s {value} success!")
        except Exception as e:
            logging.error(f"excute input {ele}'s {value} failed!")

    #点击页面元素
    # loc：定位方式, 定位的值
    def click_page_element(self,loc:tuple):
        self.find_page_element(loc).click()

    #获取页面的元素文本值
    # 需要返回值
    def get_page_element_text(self,loc:tuple):
        return self.find_page_element(loc).text

    #鼠标点击事件
    def mouse_click(self,loc:tuple):
        ActionChains(self.__driver).click(self.find_page_element(loc)).perform()

if __name__ == '__main__':
       # 解包
       def add2(a, b):
           print(a, b)
       c=(1,2)   #元组
       add2(*c)








